package com.rpa.secure.servicerpasecure.common.result;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.io.Serializable;

/**
 * 后端统一返回结果
 * @param <T>
 */
@Data
@Schema(description = "接口返回对象")
public class Result<T> implements Serializable {
    @Schema(description = "1--成功/0--失败")
    private Integer code;
    @Schema(description = "返回结果对象")
    private T data;
    @Schema(description="错误信息")
    private String msg;//错误信息

    public static <T>Result<T> success(){
        Result<T> result=new Result<>();
        result.code=1;
        return result;
    }

    public static <T>Result<T> success(T obj){
        Result<T> result=new Result<>();
        result.code=1;
        result.data=obj;
        return result;    }

    public static <T>Result<T> error(String msg){
        Result<T> result=new Result<>();
        result.code=0;
        result.msg=msg;
        return result;
    }

}
